#!/usr/bin/python2.7
#
# Copyright 2011 Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

'''
Created on Dec 7, 2011

@author: ibrahimelfar
'''

#from django.template import Context
import django.template.loader

class Activity:
    def __init__(self, name, language = '', context = '', utterances = {}, pattern_variables = {}, apps = {}):
        self.name = name
        self.language = language
        self.context = context
        self.utterances = utterances
        self.pattern_variables = pattern_variables
        self.apps = apps

class Application:
    def __init__(self, steps = []):
        self.steps = steps

class Registry:
    activities = []
    
    def register(self, activity):
        self.activities.append(activity)
        
    def register_context(self, context):
        self.context = context

class MasterRegistry:
    registries = {}
    
    def register(self, language, registry):
        self.registries[language] = registry

master_registry = MasterRegistry()


def import_language_modules(user_settings):
    for language in user_settings.languages:
        __import__('prototype.languages.' + language, fromlist = ['prototype.languages'])
        

def generate_commands(user_settings):
    for language in user_settings.languages:
        for activity in master_registry.registries[language].activities:
            print activity.utterances
            print "yes!!!!"

    
    for language in user_settings.languages:
        print language
        print user_settings
        a = master_registry.registries[language].activities
        t = dict(vars(user_settings).items() + {'activities': a}.items())
        t['variables'] = master_registry.registries[language].context['variables']
        print t
        print django.template.loader.render_to_string('commands.xml', django.template.Context(t))
